<?php
    header("Content-type: text/html; charset=utf-8");
    require_once('dbconnect.inc.php');
    require_once('auth.inc.php');

    $auth = new auth();

    $auth->setDefRedir('index.php');

    $user = $auth->isauth($dbh,$_COOKIE, false);

    if (!$user)
    {
        header($auth->getAuthRedir());  
        $cookie = $auth->getCookie();
        setcookie($cookie['name'], $cookie['value']);
        exit();
    }
    else
    {
        switch($user['role']) 
        {
            case $auth->auth_role_user:
                header('Location:monitor.php');
            break;

            case $auth->auth_role_disp:
                header('Location:monitor.php');
            break;

            case $auth->auth_role_eng:
                header('Location:cmap.php');
            break;

            case $auth->auth_role_adm:
                header('Location:users.php');
            break;

            default:
                header('Location:logout.php');
            break;
        }

    }


?>
